package com.yhs.best;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class Contact extends Activity{

	Button send;
	String subj, text;
	Spinner spinner;
	int sel;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.contact);
		sel = 0;
		send = (Button) findViewById(R.id.bSend);
		spinner = (Spinner) findViewById(R.id.cSpinner);
		
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
		        R.array.contact_array, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(adapter);
		spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
		    @Override
		    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
		       sel = position;
		    }
		    @Override
		    public void onNothingSelected(AdapterView<?> parentView) {   
		    }
		});
		
		
		send.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				final EditText subjectField = (EditText) findViewById(R.id.subj);  
				String subject = subjectField.getText().toString();  
				
				final EditText feedbackField = (EditText) findViewById(R.id.text);  
				String text = feedbackField.getText().toString();  
				
				
				Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
				String[] recipients = null;
				if(sel == 0){
					recipients = new String[]{"bestemmietors@gmail.com"};
					emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);}
				if(sel == 1){
					recipients = new String[]{"renzoni.nicolo@gmail.com"};
					emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "AppBest:"+subject);}
				
				emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);				
				emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
				emailIntent.setType("text/plain");
				startActivity(Intent.createChooser(emailIntent, "Send mail client :"));
				finish();
			}
		});
	}

}
